//
//  UITestViewController.m
//  iOSCodeLearning
//
//  Created by TFAppleWork-Summer on 2018/3/21.
//  Copyright © 2018年 Ace. All rights reserved.
//

#import "UITestViewController.h"
#import <Masonry.h>
#import "UIColor+Ex.h"
@interface UITestViewController ()

@property (nonatomic, strong) UITextField *phoneTextField;

@property (nonatomic, strong) UITextField *pwdTextField;

@property (nonatomic, strong) UIButton *loginBtn;

/**
 私有字符串
 */
@property (nonatomic, copy) NSString *privateString;

@end

@implementation UITestViewController

-(instancetype)init{
    if (self = [super init]) {
          self.privateString = @"私有属性";
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    
//    self.phoneTextField.frame = CGRectMake(0, 0, 200, 40);
//    self.phoneTextField.center = CGPointMake(CGRectGetWidth(self.view.frame)/2, 100);
//    
//    
//    self.pwdTextField.frame = CGRectMake(0, 0, 200, 40);
//    self.pwdTextField.center = CGPointMake(CGRectGetWidth(self.view.frame)/2, 160);

    
    [self.view addSubview:self.phoneTextField];
    [self.view addSubview:self.pwdTextField];
    [self.view addSubview:self.loginBtn];
    
    [self.phoneTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(40);
        make.centerX.equalTo(self.view);
        make.top.mas_equalTo(80);
        
    }];
    
    [self.pwdTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(40);
        make.top.mas_equalTo(160);
        make.centerX.equalTo(self.view);
    }];

    [self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(40);
        make.top.equalTo(self.pwdTextField.mas_bottom).offset(20);
        make.centerX.equalTo(self.view);
    }];
    
}

-(NSInteger)getNumWith:(NSInteger)a andB:(NSInteger)b{
    return a + b;
    
}

- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
    
    UIGraphicsBeginImageContext(newSize);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

#pragma mark - action
-(void)loginBtnClick:(UIButton *)button{
//
    button.enabled = NO;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        button.enabled = YES;
    });
    
    button.backgroundColor = [UIColor randomColor];
    
}

#pragma mark - private
-(NSString *)privateFuc{
    return @"1111111";
}

#pragma mark - lazy -load
-(UITextField*)phoneTextField{
    if (!_phoneTextField) {
        _phoneTextField = [[UITextField alloc] init];
        _phoneTextField.placeholder = @"请输入手机号";
        _phoneTextField.backgroundColor = [UIColor orangeColor];
    }
    return _phoneTextField;
}


-(UITextField*)pwdTextField{
    if (!_pwdTextField) {
        _pwdTextField = [[UITextField alloc] init];
        _pwdTextField.placeholder = @"请输入密码";
        _pwdTextField.backgroundColor = [UIColor orangeColor];
    }
    return _pwdTextField;
}

-(UIButton*)loginBtn{
    if (!_loginBtn) {
        _loginBtn = [[UIButton alloc] init];
        [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
        [_loginBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _loginBtn.backgroundColor = [UIColor cyanColor];
        [_loginBtn addTarget:self action:@selector(loginBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _loginBtn;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
